home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fritz: All Fritz
/
All Fritz.zip
/
All Fritz
/
FILES
/
PROGNG_C
/
CUG187.LZH
/
ITOA.C
< prev
next >
Wrap
Text File
|
1985-12-30
|
1KB
|
35 lines
/*@*****************************************************/
/*@ */
/*@ itoa - convert integer to ascii. Stolen from K & R */
/*@ Very useful to prevent loading of printf */
/*@ and the 2-8K of follow-ons. */
/*@ */
/*@ Usage: itoa(num, buffer); */
/*@ where num is an integer. */
/*@ buffer is a char area large enough to */
/*@ to hold the resulting string. */
/*@ */
/*@ Returns a pointer to the buffer. This allows */
/*@ nesting of puts(itoa(n, buffer)); variety. */
/*@ */
/*@*****************************************************/
char *itoa(n,s) /* convert n to characters in s */
char s[];
int n;
{
int i,sign;
if ((sign = n) < 0) /* record sign */
n = -n; /* make positive */
i = 0;
do { /* generate digits in reverse order */
s[i++] = n % 10 + '0'; /* get next digit */
} while ((n /= 10) > 0); /* delete it */
if (sign < 0)
s[i++] = '-';
s[i] = '\0';
reverse(s);
return s;
}